<template>
  <div class="about">
    <h1>This is Home</h1>
    <div>
      <h2>Username: {{ user.username }}</h2>
      <h2>Token: {{ token }}</h2>
      <el-button type="danger" @click="logout">Logout</el-button>
    </div>
  </div>
</template>
<script>
import {mapState} from "vuex";
import {getToken} from "@/utils/auth";

export default {
  name: 'Home',
  computed: {
    token: function () {
      return getToken()
    },
    ...mapState('user', ['user']),
  },
  methods: {
    logout() {
      this.$store.dispatch('user/logout').then(() => {
        this.$router.push('/login');
      })
    }
  }
}
</script>
